/**
  ******************************************************************************
  * @file    Config.h
  * @brief   常用宏定义
  * @version V1.0
  * @author  weiyl
  * @date    2022-09-16 10:29:16
  ******************************************************************************
  * @remark 配置文件
    Default encoding UTF-8
  ******************************************************************************
  */

#ifndef _CONFIG_H_
#define _CONFIG_H_

#include "stm32f10x.h"
#include <stdio.h>
// #include "UsartDebug.h"

//-------------------------------------------------------------------------------------------------------
//<<< Use Configuration Wizard in Context Menu >>>
//-------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------

// <e>按键使能
#define KEY_EN                                                            1
// </e>

// <e>OLED使能
#define OLED_EN                                                           1
// </e>

// <e>WIFI通信使能
#define WIFI_COMM_EN                                                      0
// </e>

// <e>AT使能
#define AT_EN                                                             0
// </e>


// <e>蓝牙调试
#define USE_ANO_PROTOCOL                                                  1
// </e>


#if defined USE_DEBUG_OUT

#define DEBUG_OUT              DEBUG_PRINTF

#elif defined __GNUC__

#define DEBUG_OUT(format, ...)         (void)(format, ##__VA_ARGS__)

#else

#define DEBUG_OUT(...)

#endif


#define HARDWARE_VERSION                    "VER123T" 
#define SOFTWARE_VERSION                    "220916"
#if (TEST_MODE ) || ( OPEN_WATCH_DOG)
#define PHASE_VERSION                       "_Test";
#else
#define PHASE_VERSION                       "_Beta";
#endif
#define VERSION_NAME_MAX_SIZE               32U
//版本号    = 硬件版本号 + 软件版本号 + 阶段版本号
//const char SysVersion[VERSION_NAME_MAX_SIZE] = HARDWARE_VERSION SOFTWARE_VERSION PHASE_VERSION;

//typedef signed long long                    int64_t;
typedef unsigned long long                  uint64_t;
// typedef unsigned long                       size_t;
typedef signed int                          int32_t;
typedef unsigned int                        uint32_t;
typedef signed short                        int16_t;
typedef unsigned short                      uint16_t;
typedef signed char                         int8_t;
typedef unsigned char                       uint8_t;

#ifndef TRUE
#define TRUE                                (1)
#define FALSE                               (0)
#endif

//宏求大小
#define MY_SIZEOF(_T_)                      ((uint32_t)((typeof(_T_)*)0 + 1))

//求结构体成员偏移值
#define OFFSETOF(TYPE, MEMBER)              ((long)(&(((TYPE *)0)->MEMBER)))

//求数组成员个数
#define ARRAY_LEN(ARRAY_NAME)   \
    (sizeof(ARRAY_NAME) / sizeof(ARRAY_NAME[0]))

//获取数组结尾地址，  注意类型
#define GET_ARRAY_TAIL_ADDR(ARRAY_NAME) \
        ((void*)((char*)(&(ARRAY_NAME) + 1 ) - 1))

//获取数组最后一个元素地址
#define GET_ARRAY_LAST_ELEMENT_ADDR(ARRAY_NAME,_TYPE_)  \
    (((_TYPE_*)(&(ARRAY_NAME) + 1 ) - 1))

//求整形差，避免溢出
#define UINT32DIFF(start, end)  \
        (((end) >= (start))? ((end) - (start)) : ((uint32_t)(-1) - (start) + (end)))


// #define SET_BIT(_Val_,_Bit_)                ((_Val_) |= (1 << (_Bit_)))
// #define CLEAN_BIT(_Val_,_Bit_)              ((_Val_) &= (~(1 << (_Bit_))))
// #define GET_BIT(_Val_,_Bit_)                (((_Val_) >> (_Bit_)) & 0x0001)

#define BigLittleSwap16(_16t_)              ((((uint16_t)(_16t_) & 0xff00) >> 8) | \
                                            (((uint16_t)(_16t_) & 0x00ff) << 8))

#define BigLittleSwap32(_32t_)              ((((uint32_t)(_32t_) & 0xff000000) >> 24) | \
                                            (((uint32_t)(_32t_) & 0x00ff0000) >> 8) | \
                                            (((uint32_t)(_32t_) & 0x0000ff00) << 8) | \
                                            (((uint32_t)(_32t_) & 0x000000ff) << 24))

#define TEST_TASK_PERIOD                    (10U)
#define TEST_TASK_DELAY_MS(_ms_)            (((_ms_) > TEST_TASK_PERIOD) ? ((_ms_) / TEST_TASK_PERIOD -1) : 0)



//0,不支持ucos
//1,支持ucos
#define SYSTEM_SUPPORT_OS		0		//定义系统文件夹是否支持UCOS																    
	 
//位带操作,实现51类似的GPIO控制功能
//具体实现思想,参考<<CM3权威指南>>第五章(87页~92页).
//IO口操作宏定义
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr)) 
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum)) 
//IO口地址映射
#define GPIOA_ODR_Addr    (GPIOA_BASE+12) //0x4001080C 
#define GPIOB_ODR_Addr    (GPIOB_BASE+12) //0x40010C0C 
#define GPIOC_ODR_Addr    (GPIOC_BASE+12) //0x4001100C 
#define GPIOD_ODR_Addr    (GPIOD_BASE+12) //0x4001140C 
#define GPIOE_ODR_Addr    (GPIOE_BASE+12) //0x4001180C 
#define GPIOF_ODR_Addr    (GPIOF_BASE+12) //0x40011A0C    
#define GPIOG_ODR_Addr    (GPIOG_BASE+12) //0x40011E0C    

#define GPIOA_IDR_Addr    (GPIOA_BASE+8) //0x40010808 
#define GPIOB_IDR_Addr    (GPIOB_BASE+8) //0x40010C08 
#define GPIOC_IDR_Addr    (GPIOC_BASE+8) //0x40011008 
#define GPIOD_IDR_Addr    (GPIOD_BASE+8) //0x40011408 
#define GPIOE_IDR_Addr    (GPIOE_BASE+8) //0x40011808 
#define GPIOF_IDR_Addr    (GPIOF_BASE+8) //0x40011A08 
#define GPIOG_IDR_Addr    (GPIOG_BASE+8) //0x40011E08 
 
//IO口操作,只对单一的IO口!
//确保n的值小于16!
#define PAout(n)   BIT_ADDR(GPIOA_ODR_Addr,n)  //输出 
#define PAin(n)    BIT_ADDR(GPIOA_IDR_Addr,n)  //输入 

#define PBout(n)   BIT_ADDR(GPIOB_ODR_Addr,n)  //输出 
#define PBin(n)    BIT_ADDR(GPIOB_IDR_Addr,n)  //输入 

#define PCout(n)   BIT_ADDR(GPIOC_ODR_Addr,n)  //输出 
#define PCin(n)    BIT_ADDR(GPIOC_IDR_Addr,n)  //输入 

#define PDout(n)   BIT_ADDR(GPIOD_ODR_Addr,n)  //输出 
#define PDin(n)    BIT_ADDR(GPIOD_IDR_Addr,n)  //输入 

#define PEout(n)   BIT_ADDR(GPIOE_ODR_Addr,n)  //输出 
#define PEin(n)    BIT_ADDR(GPIOE_IDR_Addr,n)  //输入

#define PFout(n)   BIT_ADDR(GPIOF_ODR_Addr,n)  //输出 
#define PFin(n)    BIT_ADDR(GPIOF_IDR_Addr,n)  //输入

#define PGout(n)   BIT_ADDR(GPIOG_ODR_Addr,n)  //输出 
#define PGin(n)    BIT_ADDR(GPIOG_IDR_Addr,n)  //输入




#endif

/*---------------------------- ----------------------------E.N.D-----------------------------------------------*/
